import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';

import 'flutter_ble_plugin_platform_interface.dart';

/// An implementation of [FlutterBlePluginPlatform] that uses method channels.
class MethodChannelFlutterBlePlugin extends FlutterBlePluginPlatform {
  /// The method channel used to interact with the native platform.
  @visibleForTesting
  final methodChannel = const MethodChannel('flutter_ble_plugin');

  @override
  Future<String?> getPlatformVersion() async {
    final version =
        await methodChannel.invokeMethod<String>('getPlatformVersion');
    return version;
  }

  @override
  Future<void> startScan() async {
    return await methodChannel.invokeMethod<void>('startScan');
  }

  @override
  Future<void> stopScan() async {
    return await methodChannel.invokeMethod<void>('stopScan');
  }

  @override
  Future<bool> isScanning() async {
    final isScanning = await methodChannel.invokeMethod<bool>('isScanning');
    return isScanning ?? false;
  }

  @override
  Future<bool> connect(String deviceId) async {
    final result = await methodChannel.invokeMethod<bool>('connect', deviceId);
    return result ?? false;
  }
}
